package com.tjufe;

public class Test1 {
    public static void main(String[] args) {
        //目标：完成数字华容道的初始化和随机乱序
        start(4);
    }
    public static void start(int n) {
        int[][] arr = new int[n][n];
        //遍历二维数组，给二维数组赋值
        int count = 1;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                arr[i][j] = count;
                count++;
            }
        }
        printArray(arr);

        //打乱二维数组的顺序
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                int m = (int) (Math.random() * arr.length);
                int p = (int) (Math.random() * arr[i].length);
                int temp = arr[i][j];
                arr[i][j] = arr[m][p];
                arr[m][p] = temp;
            }
        }
        System.out.println("===========================");
        printArray(arr);


    }

    public static void printArray(int[][] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println();
        }
    }

}





